﻿Imports System.Data.SqlClient
Imports UTNComputers.clsOrden_Rma
Imports UTNComputers.clsCliente
Imports UTNComputers.daoCliente
Imports UTNComputers.clsCatalogo
Imports UTNComputers.daoCatalogo
Imports UTNComputers.clsEmpleado
Imports UTNComputers.daoEmpleado
Imports UTNComputers.clsVentas
Imports UTNComputers.daoVenta

Public Class daoOrden_Rma
    'Funcion para el alta de Orden de RMA'
    Public Function Alta(ByVal Orden_RMA As clsOrden_Rma) As Boolean
        Dim Cn As New SqlConnection
        Dim Cm As New SqlCommand

        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_ALTA_ORDEN_RMA"


            Cm.Parameters.Add("@ordrma_id", SqlDbType.Int)
            Cm.Parameters.Add("@prod_id", SqlDbType.Int)
            Cm.Parameters.Add("@cli_id", SqlDbType.Int)
            Cm.Parameters.Add("@vta_id", SqlDbType.Int)
            Cm.Parameters.Add("@nro_serie", SqlDbType.VarChar)
            Cm.Parameters.Add("@ordrma_fecha", SqlDbType.SmallDateTime)
            Cm.Parameters.Add("@ordrma_falla_cliente", SqlDbType.VarChar)
            Cm.Parameters.Add("@diagnostico", SqlDbType.VarChar)
            Cm.Parameters.Add("@desc_diagnostico", SqlDbType.VarChar)
            Cm.Parameters.Add("@emp_id", SqlDbType.Int)
            Cm.Parameters.Add("@Cod_Suc", SqlDbType.Int)

            Cm.Parameters("@ordrma_id").Value = Orden_RMA.Ordrma_Id
            Cm.Parameters("@prod_id").Value = Orden_RMA.Prod_Id
            Cm.Parameters("@cli_id").Value = Orden_RMA.Cli_Id
            Cm.Parameters("@vta_id").Value = Orden_RMA.Vta_Id
            Cm.Parameters("@nro_serie").Value = Orden_RMA.Nro_Serie
            Cm.Parameters("@ordrma_fecha").Value = Orden_RMA.Ordrma_Fecha
            Cm.Parameters("@ordrma_falla_cliente").Value = Orden_RMA.Ordrma_Falla_Cliente
            Cm.Parameters("@diagnostico").Value = Orden_RMA.Diagnostico
            Cm.Parameters("@desc_diagnostico").Value = Orden_RMA.Desc_Diagnostico
            Cm.Parameters("@emp_id").Value = Orden_RMA.Emp_Id
            Cm.Parameters("@Cod_Suc").Value = Orden_RMA.Emp_Id


            Cm.Connection = Cn

            Cm.ExecuteNonQuery()
            Cn.Close()
            Return True

        Catch ex As Exception
            Return False
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    'Funcion para la modificacion una Orden de RMA'
    Public Function Modificar(ByVal Orden_RMA As clsOrden_Rma) As Boolean
        Dim Cn As New SqlConnection
        Dim Cm As New SqlCommand

        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_MODI_ORDEN_RMA"


            Cm.Parameters.Add("@ordrma_id", SqlDbType.Int)
            Cm.Parameters.Add("@prod_id", SqlDbType.Int)
            Cm.Parameters.Add("@cli_id", SqlDbType.Int)
            Cm.Parameters.Add("@vta_id", SqlDbType.Int)
            Cm.Parameters.Add("@nro_serie", SqlDbType.VarChar)
            Cm.Parameters.Add("@ordrma_fecha", SqlDbType.SmallDateTime)
            Cm.Parameters.Add("@ordrma_falla_cliente", SqlDbType.VarChar)
            Cm.Parameters.Add("@diagnostico", SqlDbType.VarChar)
            Cm.Parameters.Add("@desc_diagnostico", SqlDbType.VarChar)
            Cm.Parameters.Add("@emp_id", SqlDbType.Int)
            Cm.Parameters.Add("@Cod_Suc", SqlDbType.Int)

            Cm.Parameters("@ordrma_id").Value = Orden_RMA.Ordrma_Id
            Cm.Parameters("@prod_id").Value = Orden_RMA.Prod_Id
            Cm.Parameters("@cli_id").Value = Orden_RMA.Cli_Id
            Cm.Parameters("@vta_id").Value = Orden_RMA.Vta_Id
            Cm.Parameters("@nro_serie").Value = Orden_RMA.Nro_Serie
            Cm.Parameters("@ordrma_fecha").Value = Orden_RMA.Ordrma_Fecha
            Cm.Parameters("@ordrma_falla_cliente").Value = Orden_RMA.Ordrma_Falla_Cliente
            Cm.Parameters("@diagnostico").Value = Orden_RMA.Diagnostico
            Cm.Parameters("@desc_diagnostico").Value = Orden_RMA.Desc_Diagnostico
            Cm.Parameters("@emp_id").Value = Orden_RMA.Emp_Id
            Cm.Parameters("@Cod_Suc").Value = Orden_RMA.Emp_Id


            Cm.Connection = Cn

            Cm.ExecuteNonQuery()
            Cn.Close()
            Return True

        Catch ex As Exception
            Return False
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    'Funcion para Traer una Orden de RMA por ID'
    Public Function TraeOrdenRMA(ByVal ordrma_id As Integer) As clsOrden_Rma
        Dim Cn As New SqlClient.SqlConnection
        Dim Cm As New SqlClient.SqlCommand
        Dim Dr As SqlClient.SqlDataReader
        Dim Orden_RMA As New clsOrden_Rma()

        Dim Conf As New clsConfiguraciones()
        Dim dao_Conf As New daoConfiguraciones()
        Conf = dao_Conf.TraeConfiguraciones()

        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_TRAER_ORDEN_RMA"

            Cm.Parameters.Add("@ordrma_id", SqlDbType.Int)
            Cm.Parameters("@ordrma_id").Value = ordrma_id

            Cm.Parameters.Add("@Cod_Suc", SqlDbType.Int)
            Cm.Parameters("@Cod_Suc").Value = Conf.Cod_Suc

            Cm.Connection = Cn
            Dr = Cm.ExecuteReader
            If Dr.HasRows = True Then
                While Dr.Read
                    Orden_RMA.Ordrma_Id = Dr.GetInt32(0)
                    Orden_RMA.Prod_Id = Dr.GetInt32(1)

                    If Dr.IsDBNull(2) Then
                        Orden_RMA.Cli_Id = 0
                    Else
                        Orden_RMA.Cli_Id = Dr.GetInt32(2)
                    End If

                    Orden_RMA.Vta_Id = Dr.GetInt32(3)

                    If Dr.IsDBNull(4) Then
                        Orden_RMA.Nro_Serie = "-"
                    Else
                        Orden_RMA.Nro_Serie = Dr.GetString(4).Trim.ToUpper
                    End If

                    Orden_RMA.Ordrma_Fecha = Dr.GetDateTime(5)

                    If Dr.IsDBNull(6) Then
                        Orden_RMA.Ordrma_Falla_Cliente = "-"
                    Else
                        Orden_RMA.Ordrma_Falla_Cliente = Dr.GetString(6).Trim.ToUpper
                    End If

                    Orden_RMA.Diagnostico = Dr.GetString(7).Trim.ToUpper

                    If Dr.IsDBNull(8) Then
                        Orden_RMA.Desc_Diagnostico = "-"
                    Else
                        Orden_RMA.Desc_Diagnostico = Dr.GetString(8).Trim.ToUpper
                    End If

                    If Dr.IsDBNull(9) Then
                        Orden_RMA.Emp_Id = 0
                    Else
                        Orden_RMA.Emp_Id = Dr.GetInt32(9)
                    End If
                    Orden_RMA.Cod_Suc = Dr.GetInt32(10)

                    If (Orden_RMA.Cli_Id > 0) Then
                        Dim Cliente_Dao As New daoCliente()
                        Orden_RMA.Cliente = Cliente_Dao.TraeCliente(Orden_RMA.Cli_Id)
                        Cliente_Dao.Dispose()
                    Else
                        Orden_RMA.Cliente = New clsCliente()
                    End If

                    Dim Catalogo_Dao As New daoCatalogo()
                    Orden_RMA.Producto = Catalogo_Dao.TraeArticulo(Orden_RMA.Prod_Id)
                    Catalogo_Dao.Dispose()

                    Dim Venta_Dao As New daoVenta()
                    Orden_RMA.Venta = Venta_Dao.TraeVenta(Orden_RMA.Vta_Id)
                    Venta_Dao.Dispose()

                    If (Orden_RMA.Emp_Id > 0) Then
                        Dim Empleado_Dao As New daoEmpleado()
                        Orden_RMA.Empleado = Empleado_Dao.TraeEmpleado(Orden_RMA.Emp_Id)
                        Empleado_Dao.Dispose()
                    Else
                        Orden_RMA.Empleado = New clsEmpleado()
                    End If
                End While

                Dr.Close()
                Cn.Close()
            End If
            Return Orden_RMA
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    'Funcion para Traer Todas los Ordenes de RMA por Rango de Fecha'
    Public Function TraeOrdenesRMA(ByVal fec_Desde As Date, ByVal fec_Hasta As Date) As List(Of clsOrden_Rma)
        Dim Cn As New SqlClient.SqlConnection
        Dim Cm As New SqlClient.SqlCommand
        Dim Dr As SqlClient.SqlDataReader
        Dim ListaOrden_RMA As New List(Of clsOrden_Rma)

        Dim Conf As New clsConfiguraciones()
        Dim dao_Conf As New daoConfiguraciones()
        Conf = dao_Conf.TraeConfiguraciones()

        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_TRAER_ORDEN_RMA_X_FECHA"

            Cm.Parameters.Add("@fecha_desde", SqlDbType.SmallDateTime)
            Cm.Parameters.Add("@fecha_hasta", SqlDbType.SmallDateTime)
            Cm.Parameters("@fecha_desde").Value = fec_Desde
            Cm.Parameters("@fecha_hasta").Value = fec_Hasta
            Cm.Parameters.Add("@Cod_Suc", SqlDbType.Int)
            Cm.Parameters("@Cod_Suc").Value = Conf.Cod_Suc

            Cm.Connection = Cn
            Dr = Cm.ExecuteReader
            If Dr.HasRows = True Then
                While Dr.Read
                    Dim Orden_RMA As New clsOrden_Rma()
                    Orden_RMA.Ordrma_Id = Dr.GetInt32(0)
                    Orden_RMA.Prod_Id = Dr.GetInt32(1)

                    If Dr.IsDBNull(2) Then
                        Orden_RMA.Cli_Id = 0
                    Else
                        Orden_RMA.Cli_Id = Dr.GetInt32(2)
                    End If

                    Orden_RMA.Vta_Id = Dr.GetInt32(3)

                    If Dr.IsDBNull(4) Then
                        Orden_RMA.Nro_Serie = "-"
                    Else
                        Orden_RMA.Nro_Serie = Dr.GetString(4).Trim.ToUpper
                    End If

                    Orden_RMA.Ordrma_Fecha = Dr.GetDateTime(5)

                    If Dr.IsDBNull(6) Then
                        Orden_RMA.Ordrma_Falla_Cliente = "-"
                    Else
                        Orden_RMA.Ordrma_Falla_Cliente = Dr.GetString(6).Trim.ToUpper
                    End If

                    Orden_RMA.Diagnostico = Dr.GetString(7).Trim.ToUpper

                    If Dr.IsDBNull(8) Then
                        Orden_RMA.Desc_Diagnostico = "-"
                    Else
                        Orden_RMA.Desc_Diagnostico = Dr.GetString(8).Trim.ToUpper
                    End If

                    If Dr.IsDBNull(9) Then
                        Orden_RMA.Emp_Id = 0
                    Else
                        Orden_RMA.Emp_Id = Dr.GetInt32(9)
                    End If
                    Orden_RMA.Cod_Suc = Dr.GetInt32(10)

                    If (Orden_RMA.Cli_Id > 0) Then
                        Dim Cliente_Dao As New daoCliente()
                        Orden_RMA.Cliente = Cliente_Dao.TraeCliente(Orden_RMA.Cli_Id)
                        Cliente_Dao.Dispose()
                    Else
                        Orden_RMA.Cliente = New clsCliente()
                    End If

                    Dim Catalogo_Dao As New daoCatalogo()
                    Orden_RMA.Producto = Catalogo_Dao.TraeArticulo(Orden_RMA.Prod_Id)
                    Catalogo_Dao.Dispose()

                    Dim Venta_Dao As New daoVenta()
                    Orden_RMA.Venta = Venta_Dao.TraeVenta(Orden_RMA.Vta_Id)
                    Venta_Dao.Dispose()

                    If (Orden_RMA.Emp_Id > 0) Then
                        Dim Empleado_Dao As New daoEmpleado()
                        Orden_RMA.Empleado = Empleado_Dao.TraeEmpleado(Orden_RMA.Emp_Id)
                        Empleado_Dao.Dispose()
                    Else
                        Orden_RMA.Empleado = New clsEmpleado()
                    End If

                    ListaOrden_RMA.Add(Orden_RMA)
                    Orden_RMA.Dispose()
                End While

                Dr.Close()
                Cn.Close()
            End If
            Return ListaOrden_RMA
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    'Funcion para Traer Todas los Ordenes de RMA por Cliente'
    Public Function TraeOrdenesRMA(ByVal Cliente As clsCliente) As List(Of clsOrden_Rma)
        Dim Cn As New SqlClient.SqlConnection
        Dim Cm As New SqlClient.SqlCommand
        Dim Dr As SqlClient.SqlDataReader
        Dim ListaOrden_RMA As New List(Of clsOrden_Rma)

        Dim Conf As New clsConfiguraciones()
        Dim dao_Conf As New daoConfiguraciones()
        Conf = dao_Conf.TraeConfiguraciones()

        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_TRAER_ORDEN_RMA_X_CLIENTE"

            Cm.Parameters.Add("@cli_id", SqlDbType.SmallDateTime)
            Cm.Parameters("@cli_id").Value = Cliente.Cli_Id
            Cm.Parameters.Add("@Cod_Suc", SqlDbType.Int)
            Cm.Parameters("@Cod_Suc").Value = Conf.Cod_Suc

            Cm.Connection = Cn
            Dr = Cm.ExecuteReader
            If Dr.HasRows = True Then
                While Dr.Read
                    Dim Orden_RMA As New clsOrden_Rma()
                    Orden_RMA.Ordrma_Id = Dr.GetInt32(0)
                    Orden_RMA.Prod_Id = Dr.GetInt32(1)

                    If Dr.IsDBNull(2) Then
                        Orden_RMA.Cli_Id = 0
                    Else
                        Orden_RMA.Cli_Id = Dr.GetInt32(2)
                    End If

                    Orden_RMA.Vta_Id = Dr.GetInt32(3)

                    If Dr.IsDBNull(4) Then
                        Orden_RMA.Nro_Serie = "-"
                    Else
                        Orden_RMA.Nro_Serie = Dr.GetString(4).Trim.ToUpper
                    End If

                    Orden_RMA.Ordrma_Fecha = Dr.GetDateTime(5)

                    If Dr.IsDBNull(6) Then
                        Orden_RMA.Ordrma_Falla_Cliente = "-"
                    Else
                        Orden_RMA.Ordrma_Falla_Cliente = Dr.GetString(6).Trim.ToUpper
                    End If

                    Orden_RMA.Diagnostico = Dr.GetString(7).Trim.ToUpper

                    If Dr.IsDBNull(8) Then
                        Orden_RMA.Desc_Diagnostico = "-"
                    Else
                        Orden_RMA.Desc_Diagnostico = Dr.GetString(8).Trim.ToUpper
                    End If

                    If Dr.IsDBNull(9) Then
                        Orden_RMA.Emp_Id = 0
                    Else
                        Orden_RMA.Emp_Id = Dr.GetInt32(9)
                    End If

                    If (Orden_RMA.Cli_Id > 0) Then
                        Dim Cliente_Dao As New daoCliente()
                        Orden_RMA.Cliente = Cliente_Dao.TraeCliente(Orden_RMA.Cli_Id)
                        Cliente_Dao.Dispose()
                    Else
                        Orden_RMA.Cliente = New clsCliente()
                    End If
                    Orden_RMA.Cod_Suc = Dr.GetInt32(10)

                    Dim Catalogo_Dao As New daoCatalogo()
                    Orden_RMA.Producto = Catalogo_Dao.TraeArticulo(Orden_RMA.Prod_Id)
                    Catalogo_Dao.Dispose()

                    Dim Venta_Dao As New daoVenta()
                    Orden_RMA.Venta = Venta_Dao.TraeVenta(Orden_RMA.Vta_Id)
                    Venta_Dao.Dispose()

                    If (Orden_RMA.Emp_Id > 0) Then
                        Dim Empleado_Dao As New daoEmpleado()
                        Orden_RMA.Empleado = Empleado_Dao.TraeEmpleado(Orden_RMA.Emp_Id)
                        Empleado_Dao.Dispose()
                    Else
                        Orden_RMA.Empleado = New clsEmpleado()
                    End If

                    ListaOrden_RMA.Add(Orden_RMA)
                    Orden_RMA.Dispose()
                End While

                Dr.Close()
                Cn.Close()
            End If
            Return ListaOrden_RMA
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    'Funcion para Traer Todas los Ordenes de RMA por Empleado'
    Public Function TraeOrdenesRMA(ByVal Empleado As clsEmpleado) As List(Of clsOrden_Rma)
        Dim Cn As New SqlClient.SqlConnection
        Dim Cm As New SqlClient.SqlCommand
        Dim Dr As SqlClient.SqlDataReader
        Dim ListaOrden_RMA As New List(Of clsOrden_Rma)

        Dim Conf As New clsConfiguraciones()
        Dim dao_Conf As New daoConfiguraciones()
        Conf = dao_Conf.TraeConfiguraciones()

        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_TRAER_ORDEN_RMA_X_EMPLEADO"

            Cm.Parameters.Add("@emp_id", SqlDbType.SmallDateTime)
            Cm.Parameters("@emp_id").Value = Empleado.Emp_Id
            Cm.Parameters.Add("@Cod_Suc", SqlDbType.Int)
            Cm.Parameters("@Cod_Suc").Value = Conf.Cod_Suc

            Cm.Connection = Cn
            Dr = Cm.ExecuteReader
            If Dr.HasRows = True Then
                While Dr.Read
                    Dim Orden_RMA As New clsOrden_Rma()
                    Orden_RMA.Ordrma_Id = Dr.GetInt32(0)
                    Orden_RMA.Prod_Id = Dr.GetInt32(1)

                    If Dr.IsDBNull(2) Then
                        Orden_RMA.Cli_Id = 0
                    Else
                        Orden_RMA.Cli_Id = Dr.GetInt32(2)
                    End If

                    Orden_RMA.Vta_Id = Dr.GetInt32(3)

                    If Dr.IsDBNull(4) Then
                        Orden_RMA.Nro_Serie = "-"
                    Else
                        Orden_RMA.Nro_Serie = Dr.GetString(4).Trim.ToUpper
                    End If

                    Orden_RMA.Ordrma_Fecha = Dr.GetDateTime(5)

                    If Dr.IsDBNull(6) Then
                        Orden_RMA.Ordrma_Falla_Cliente = "-"
                    Else
                        Orden_RMA.Ordrma_Falla_Cliente = Dr.GetString(6).Trim.ToUpper
                    End If

                    Orden_RMA.Diagnostico = Dr.GetString(7).Trim.ToUpper

                    If Dr.IsDBNull(8) Then
                        Orden_RMA.Desc_Diagnostico = "-"
                    Else
                        Orden_RMA.Desc_Diagnostico = Dr.GetString(8).Trim.ToUpper
                    End If

                    If Dr.IsDBNull(9) Then
                        Orden_RMA.Emp_Id = 0
                    Else
                        Orden_RMA.Emp_Id = Dr.GetInt32(9)
                    End If
                    Orden_RMA.Cod_Suc = Dr.GetInt32(10)

                    If (Orden_RMA.Cli_Id > 0) Then
                        Dim Cliente_Dao As New daoCliente()
                        Orden_RMA.Cliente = Cliente_Dao.TraeCliente(Orden_RMA.Cli_Id)
                        Cliente_Dao.Dispose()
                    Else
                        Orden_RMA.Cliente = New clsCliente()
                    End If

                    Dim Catalogo_Dao As New daoCatalogo()
                    Orden_RMA.Producto = Catalogo_Dao.TraeArticulo(Orden_RMA.Prod_Id)
                    Catalogo_Dao.Dispose()

                    Dim Venta_Dao As New daoVenta()
                    Orden_RMA.Venta = Venta_Dao.TraeVenta(Orden_RMA.Vta_Id)
                    Venta_Dao.Dispose()

                    If (Orden_RMA.Emp_Id > 0) Then
                        Dim Empleado_Dao As New daoEmpleado()
                        Orden_RMA.Empleado = Empleado_Dao.TraeEmpleado(Orden_RMA.Emp_Id)
                        Empleado_Dao.Dispose()
                    Else
                        Orden_RMA.Empleado = New clsEmpleado()
                    End If

                    ListaOrden_RMA.Add(Orden_RMA)
                    Orden_RMA.Dispose()
                End While

                Dr.Close()
                Cn.Close()
            End If
            Return ListaOrden_RMA
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    'Funcion para Traer Todas los Ordenes de RMA por Articulo'
    Public Function TraeOrdenesRMA(ByVal Articulo As clsCatalogo) As List(Of clsOrden_Rma)
        Dim Cn As New SqlClient.SqlConnection
        Dim Cm As New SqlClient.SqlCommand
        Dim Dr As SqlClient.SqlDataReader
        Dim ListaOrden_RMA As New List(Of clsOrden_Rma)

        Dim Conf As New clsConfiguraciones()
        Dim dao_Conf As New daoConfiguraciones()
        Conf = dao_Conf.TraeConfiguraciones()


        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_TRAER_ORDEN_RMA_X_ARTICULO"

            Cm.Parameters.Add("@prod_id", SqlDbType.SmallDateTime)
            Cm.Parameters("@prod_id").Value = Articulo.Prod_Id
            Cm.Parameters.Add("@Cod_Suc", SqlDbType.Int)
            Cm.Parameters("@Cod_Suc").Value = Conf.Cod_Suc

            Cm.Connection = Cn
            Dr = Cm.ExecuteReader
            If Dr.HasRows = True Then
                While Dr.Read
                    Dim Orden_RMA As New clsOrden_Rma()
                    Orden_RMA.Ordrma_Id = Dr.GetInt32(0)
                    Orden_RMA.Prod_Id = Dr.GetInt32(1)

                    If Dr.IsDBNull(2) Then
                        Orden_RMA.Cli_Id = 0
                    Else
                        Orden_RMA.Cli_Id = Dr.GetInt32(2)
                    End If

                    Orden_RMA.Vta_Id = Dr.GetInt32(3)

                    If Dr.IsDBNull(4) Then
                        Orden_RMA.Nro_Serie = "-"
                    Else
                        Orden_RMA.Nro_Serie = Dr.GetString(4).Trim.ToUpper
                    End If

                    Orden_RMA.Ordrma_Fecha = Dr.GetDateTime(5)

                    If Dr.IsDBNull(6) Then
                        Orden_RMA.Ordrma_Falla_Cliente = "-"
                    Else
                        Orden_RMA.Ordrma_Falla_Cliente = Dr.GetString(6).Trim.ToUpper
                    End If

                    Orden_RMA.Diagnostico = Dr.GetString(7).Trim.ToUpper

                    If Dr.IsDBNull(8) Then
                        Orden_RMA.Desc_Diagnostico = "-"
                    Else
                        Orden_RMA.Desc_Diagnostico = Dr.GetString(8).Trim.ToUpper
                    End If

                    If Dr.IsDBNull(9) Then
                        Orden_RMA.Emp_Id = 0
                    Else
                        Orden_RMA.Emp_Id = Dr.GetInt32(9)
                    End If
                    Orden_RMA.Cod_Suc = Dr.GetInt32(10)

                    If (Orden_RMA.Cli_Id > 0) Then
                        Dim Cliente_Dao As New daoCliente()
                        Orden_RMA.Cliente = Cliente_Dao.TraeCliente(Orden_RMA.Cli_Id)
                        Cliente_Dao.Dispose()
                    Else
                        Orden_RMA.Cliente = New clsCliente()
                    End If

                    Dim Catalogo_Dao As New daoCatalogo()
                    Orden_RMA.Producto = Catalogo_Dao.TraeArticulo(Orden_RMA.Prod_Id)
                    Catalogo_Dao.Dispose()

                    Dim Venta_Dao As New daoVenta()
                    Orden_RMA.Venta = Venta_Dao.TraeVenta(Orden_RMA.Vta_Id)
                    Venta_Dao.Dispose()

                    If (Orden_RMA.Emp_Id > 0) Then
                        Dim Empleado_Dao As New daoEmpleado()
                        Orden_RMA.Empleado = Empleado_Dao.TraeEmpleado(Orden_RMA.Emp_Id)
                        Empleado_Dao.Dispose()
                    Else
                        Orden_RMA.Empleado = New clsEmpleado()
                    End If

                    ListaOrden_RMA.Add(Orden_RMA)
                    Orden_RMA.Dispose()
                End While

                Dr.Close()
                Cn.Close()
            End If
            Return ListaOrden_RMA
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    '---------------------------------------------------------------------
    ' Constructor de la Clase
    '---------------------------------------------------------------------
    Public Sub New()

        MyBase.New()

    End Sub

    '---------------------------------------------------------------------
    ' Destructor de la Clase
    '---------------------------------------------------------------------
    Public Sub Dispose()

        MyBase.Finalize()

    End Sub

End Class
